package chapter1.dataabstraction.example;

import edu.princeton.cs.algs4.Counter;
import edu.princeton.cs.algs4.StdRandom;

/**
 * @author quanlinlin on 2018/11/4 14:21.
 * @version 1.0
 */
public class Flips {

    public static void main(String[] args) {
        int T = Integer.parseInt(args[0]);
        Counter heads = new Counter("heads");
        Counter tails = new Counter("tails");
        for (int i = 0; i < T; i++) {
            if (StdRandom.bernoulli(0.5)) {
                heads.increment();
            } else {
                tails.increment();
            }
        }
        System.out.println(heads);
        System.out.println(tails);
        int d = heads.tally() - tails.tally();
        System.out.println("delta:" + Math.abs(d));

    }
}
